package com.lsm.searchservice.controller;

import com.hmall.common.pojo.dto.PageDTO;
import com.lsm.searchservice.pojo.ItemDoc;
import com.lsm.searchservice.pojo.dto.FiltersDto;
import com.lsm.searchservice.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     *根据搜索条件搜索文档，并对文档中的分类、品牌做聚合，返回聚合得到的分类、品牌信息
     * @param filtersDto
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody FiltersDto filtersDto) {
        return searchService.filters(filtersDto);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody FiltersDto filtersDto) {
        return searchService.list(filtersDto);
    }

    @GetMapping("/suggestion")
    public List<String> suggestion(String key) {
        return searchService.suggestion(key);
    }
}
